package com.hj.kim.Controller;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUtils;

import org.apache.ibatis.annotations.Param;
import org.junit.Test.None;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hj.kim.DTO.MemberDto;
import com.hj.kim.Util.HttpResponse;
import com.sun.mail.iap.Response;
/**
 * 기능 컨트롤러
 * <pre>
 * 
 * </pre>
 *
 * <pre>
 * <b>History:</b>
 *   희정, 1.0, 2014.06.26 초기작성
 * </pre>
 *
 * @author 최종 수정자
 * @version 1.0, 2014.06.26 메서드 추가함
 * @see    None
 */
@Controller
public class MemberController {
	
	private static final String DEFAULT_REQUEST_MAPPING = "/member.do";
	private static final Logger logger = LoggerFactory.getLogger(MemberController.class);
	private HttpSession loginSession = null;

	/** service */
	@Resource(name = "MemberService")
	private com.hj.kim.Service.MemberService service;

	/**
	 * 회원가입페이지 호출
	 *
	 * @param HttpServletRequest request, 리퀘스트 
	 * @param HttpServletResponse response , 리스폰스
	 * @return ModelAndView, jsp로 페이지 포워드 및 오브젝트 설정
	 * @exception 
	 */

	@RequestMapping(value = {DEFAULT_REQUEST_MAPPING}, params={"action=joinP"}, method=RequestMethod.GET)
	public String newaccountForm(HttpServletRequest request, HttpServletResponse response) {
		return "member/new_account";
	}
	@RequestMapping(value = {DEFAULT_REQUEST_MAPPING}, params={"action=checkID"}, method=RequestMethod.GET)
	public void checkID(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("param") MemberDto param) {
		int res = 0;
		res = service.checkID(param);
		HttpResponse.sendMessage(response, Integer.toString(res));
	}
	@RequestMapping(value = {DEFAULT_REQUEST_MAPPING}, params={"action=insertMember"}, method=RequestMethod.POST)
	public void insertMember(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("param") MemberDto param) {
		int res = 0;
		res = service.insertMember(param);
		HttpResponse.sendMessage(response, Integer.toString(res));
	}
	@RequestMapping(value = {DEFAULT_REQUEST_MAPPING}, params={"action=login"}, method=RequestMethod.POST)
	public void login(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("param") MemberDto param) {
		int res = 0;
		res = service.login(param);
		if(res == 1){
			loginSession = request.getSession();
			loginSession.setAttribute("ID", param.getID());
			loginSession.setAttribute("PW", param.getPW());
			res=1;
		}
		else{
			res=-1;
		}
		HttpResponse.sendMessage(response, Integer.toString(res));
	}
	

	/**
	 * 회원가입check 유무 확인 후 가입처리
	 *
	 * @param HttpServletRequest request, 리퀘스트 
	 * @param HttpServletResponse response , 리스폰스
	 * @param MemberTableDto param , 멤버 테이블 dto
	 * @return int succ, 추가된 db row개수 반환
	 * @exception 
	 */


	/**
	 * 로그인
	 *
	 * @param HttpServletRequest request, 리퀘스트 
	 * @param HttpServletResponse response , 리스폰스
	 * @param MemberTableDto param , 멤버 테이블 dto
	 * @return int succ, 아이디, 비밀번호 일치시 1 리턴 아닐땐 -1 리턴
	 * @exception 
	 */

	/**
	 * 기능데이터 수정
	 *
	 * @param HttpServletRequest request, 리퀘스트 
	 * @param HttpServletResponse response , 리스폰스
	 * @param FunctionTableDto param , 기능 테이블 dto
	 * @return int succ, 업데이트된 db row개수 반환
	 * @exception 
	 */

	
	/**
	 * 기능데이터 삭제
	 *
	 * @param HttpServletRequest request, 리퀘스트 
	 * @param HttpServletResponse response , 리스폰스
	 * @param FunctionTableDto param , 기능 테이블 dto
	 * @return int succ, 삭제된 db row개수 반환
	 * @exception 
	 */

	
}
